﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Specialized;

public partial class djxq : System.Web.UI.Page
{

    private NameValueCollection arg = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        arg = Request.Form.Count == 0 ? Request.QueryString : Request.Form;

       

        if (!IsPostBack)
        {
            if (arg["op"] != null)
            {
                del();
            }
            bind();
        }
    }

    private void del()
    {
        string id = arg["id"];
        if (id != null)
        {
            string sql = "delete from xiaoqu where id=" + id;
            string msg = "删除失败";
            if (
                DbHelper.ExecNonQuery(sql)
                )
            {
                msg = "删除成功";
            }

            Response.Write(util.GetResponseAlert(msg));
            Response.Write("<script>                        var loc = document.location.toString();if(loc.indexOf('?')!=-1)loc = loc.toString().substring(0,loc.indexOf('?'));document.location=loc;</script>");
        }
    }

    private void bind()
    {
        //查询到所有的小区
        DataTable dt = DbHelper.selectTable("xiaoqu", null);
        if (dt != null)
        {
            foreach (DataRow dr in dt.Rows)
            {
                Literal1.Text += getStr(dr["id"].ToString(),
                    dr["show_name"].ToString());
            }
        }
    }

    private string getStr(string bianHao, string mingCheng)
    {
        string cmd = "{0},\"{1}\"";
        cmd = string.Format(cmd, bianHao,
                                mingCheng);

        string str = "<tr align=\"center\" onmouseover=\"this.style.backgroundColor='#EBEBEB';\" onmouseout=\"this.style.backgroundColor='';\" style=\"\">" +
        "<td>" +
         bianHao +
        "</td>" +
        "<td>" +
        mingCheng +
        "</td>" +
        "<td>" +
        "<a onclick='del("+bianHao+")'>删除</a>&nbsp;" +
        "<a onclick='edit1(" + cmd + ")'>修改</a>" +
     "</td>" +
    "</tr>";

        return str;
    }
    protected void add_Click(object sender, EventArgs e)
    {
        string msg = "添加失败";
        if (xiaoquName.Text.Trim() != "")
        {
            string sql = "insert into xiaoqu values('" + xiaoquName.Text + "')";
            if (
                DbHelper.ExecNonQuery(sql)
                )
            {
                msg = "添加成功";
            }
            
        }
        else
        {
            msg = "请输入正确内容";
        }

        Response.Write(util.GetResponseAlert(msg));
        Response.Write("<script>document.location=document.location;</script>");
    }


    protected void edit_Click(object sender, EventArgs e)
    {
        string msg = "编辑失败";
        if (hideFild.Text.Trim() != "")
        {
            string[] arr = hideFild.Text.Split(',');

            string sql = "update xiaoqu set show_name='" + arr[1] + "' where id=" + arr[0];
            if (
                DbHelper.ExecNonQuery(sql)
                )
            {
                msg = "编辑成功";
            }

        }
        else
        {
            msg = "请输入正确内容";
        }

        Response.Write(util.GetResponseAlert(msg));
        Response.Write("<script>document.location=document.location;</script>");
    }
}
